package com.sskj.fabi.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.bean.PublishBean;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.fragment.FabiPublishRecordFragment;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;

public class FabiPublishRecordFragmentPresenter extends BasePresenter<FabiPublishRecordFragment> {

    /**
     * 获取发布订单记录列表
     */
    public void getFaBuRecord(String type, int p, int size) {
        httpService.getFaBuRecord(type, p, size)
                .execute(new JsonCallBack<HttpData<PageBean<PublishBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<PublishBean>>> response) {
                        HttpData<PageBean<PublishBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if (httpData.getData().getList().size() == 0 && p != 1) {
                                ToastUtil.showShort("亲，已经到底了");
                            } else {
                                mView.setData(httpData.getData().getList());
                            }
                        } else {
                            ToastUtil.showShort(httpData.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<PageBean<PublishBean>>> response) {
                        super.onError(response);
                    }
                });
    }

    /**
     * 取消订单
     */
    public void cancleOrder(String type, int id) {
        httpService.cancleOrder(type, id)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        mView.updateUi();
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                    }
                });
    }
}
